classdef IntervalPlotter
    %UNTITLED4 Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
		
    end
    
    methods (Static)
        function singleIntervalPlot(intervalArray,color)
			if nargin==1 
                color='green';
            end 
			[x,y]=IntervalPlotter.plot_variance(intervalArray,color);
			hold on;
			plot(x,y);
		end
		
		function multipleIntervalPlot(intervalArrays)
			arraySize=size(intervalArrays);
			arrayCount=size(1);
			arrayLength=size(2);
			colorArray=getColorArray(arrayCount);	
			x=zeros(arrayCount,arrayLength);
			y=zeros(arrayCount,arrayLength);
			for i=1:arrayCount
				[x(i,:),y(i,:)]=IntervalPlotter.plot_variance(intervalArray,colorArray(i));
			end
			hold on;
			plot(x,y);
			
		
		end
		
		function colors=getColorArray(num)
			colors=[];
			for i=1:num
				rgbInterval=Interval(0,1);
				R=Utils.getRandomFromInterval(rgbInterval);
				G=Utils.getRandomFromInterval(rgbInterval);
				B=Utils.getRandomFromInterval(rgbInterval);
				colors(i)=[R G B];
			end
		end
		
		function [x,y]=plot_variance(intervalArr,color)
			%lower=Utils.convertToArray(intervalArr, 'min');
			%upper=Utils.convertToArray(intervalArr, 'max');
			y=Utils.convertToArray(intervalArr, 'middle');
			x=1:length(intervalArr);
            for i=1:length(intervalArr)
                IntervalPlotter.fillInterval(x(i),intervalArr(i),0.1,color)
            end
			%set(fill([x,x(end:-1:1)],[upper,lower(end:-1:1)],color),'EdgeColor',color);
        end
        
        function plotIsgWithAffineAndInterval(isgArrayX, isgArrayY, affineIntervalArray, intervalArray,selectedX,selectedInterval)
			figure
			for i=1:length(isgArrayX)
                IntervalPlotter.fillInterval(isgArrayX(i),affineIntervalArray(i).convertToInterval(),0.4,'r','FaceAlpha', 0.5);
				IntervalPlotter.fillInterval(isgArrayX(i),intervalArray(i),0.4,'g','FaceAlpha', 0.5);
			end
			if nargin==6 
               IntervalPlotter.fillInterval(selectedX,selectedInterval,0.4,['b','FaceAlpha', 0.8]);
            end 
			
			plot(isgArrayX,isgArrayY);
		end
		
		function plotIntervalCurve(isgArrayX, isgArrayY, affineIntervalArray, intervalArray, selectedX,selectedInterval);
			figure
			lowerInt=Utils.convertToArray(intervalArray, 'min');
			upperInt=Utils.convertToArray(intervalArray, 'max');
			
			lowerAff=Utils.convertToArray(affineIntervalArray, 'min');
			upperAff=Utils.convertToArray(affineIntervalArray, 'max');
			
			set(fill([isgArrayX,isgArrayX(end:-1:1)],[upperInt,lowerInt(end:-1:1)],'g','FaceAlpha', 0.4),'EdgeColor','g');
			hold on;
            set(fill([isgArrayX,isgArrayX(end:-1:1)],[upperAff,lowerAff(end:-1:1)],'r','FaceAlpha', 0.4),'EdgeColor','r');
			if nargin==6 
               IntervalPlotter.fillInterval(selectedX,selectedInterval,1,'b','FaceAlpha', 0.4);
            end 
			hold on;
			plot(isgArrayX,isgArrayY);
		end
		
        function fillInterval(x,interval,width,color,param1,param2)
            arr1=[x-width , x-width , x+width , x+width];
            arr2=[interval.imin-0.005, interval.imax+0.005, interval.imax+0.005, interval.imin-0.005];
            if nargin==6
                 fill(arr1,arr2,color,param1,param2);
            else
                fill(arr1,arr2,color);
            end
            
            hold on;
        end
		
		function plotCurve(x,lower,upper,color)
				set(fill([x,x(end:-1:1)],[upper,lower(end:-1:1)],color),'EdgeColor',color);	
		end
		
		function highLightIterval()
		
    end
    
end
end
